//
//  StoreHeaderView.m
//  Lmm_IOS
//
//  Created by 张哲炜 on 2018/9/19.
//  Copyright © 2018年 lmm. All rights reserved.
//

#import "StoreHeaderView.h"

@implementation StoreHeaderView{
    
     SDCycleScrollView *cycleScrollView;
    UILabel* pointsLabel;
    UILabel* historyPointsLabel;
    NSArray * sliderArray;
}


-(void)setSliderImgUrl:(NSMutableArray * )sliderImgUrl{
    
    
    self->cycleScrollView.imageURLStringsGroup = sliderImgUrl;
    
}


- (void)setSlider :(NSArray *)slider{
    
    self->sliderArray =slider;
}


- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    
    NSLog(@"%d",index);
    SliderModel *sliderModel = [self->sliderArray objectAtIndex:index];
    
    ArticleViewController *articleViewController = ArticleViewController.new;
    articleViewController.id =sliderModel.id;
    
    //articleViewController.hidesBottomBarWhenPushed = YES;
    //[self.navigationController pushViewController:articleViewController animated:YES];
     [[[AppDelegate shareAppDelegate] shareNavigationController] pushViewController:articleViewController animated:YES];
    
}

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
  
    self.backgroundColor =[UIColor whiteColor];
        

        cycleScrollView = [ SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, MAIN_SCREEN_WIDTH, MAIN_SCREEN_WIDTH/4) delegate:self placeholderImage:nil];
        //cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        // 设置pageControl居右，默认居中
        cycleScrollView.autoScrollTimeInterval = 3;// 自定义轮播时间间隔

        [self addSubview:cycleScrollView];
        
    UIView *bottomLine = UIView.new;
    bottomLine.backgroundColor =[UIColor grayColor];
    [self addSubview:bottomLine];

    [bottomLine makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.left).offset(0);
        make.right.equalTo(self.right).offset(0);
        make.bottom.equalTo(self.bottom).offset(0);
        make.height.equalTo(1/[[UIScreen mainScreen] scale]);

    }];

        
    UIView* grayView =UIView.new;
    grayView.backgroundColor =UIColorFromRGB(0xEEEEEE);
    [self addSubview:grayView];
             
    [grayView makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(bottomLine.bottom);
        make.left.equalTo(self.left).offset(0);
        make.right.equalTo(self.right).offset(0);
        make.height.equalTo(30);
                
    }];
        
        
    UILabel* goodsLabel =UILabel.new;
    goodsLabel.text = @"兑换商品";
    goodsLabel.font =[UIFont systemFontOfSize:15];
    [grayView addSubview:goodsLabel];
        
       [goodsLabel makeConstraints:^(MASConstraintMaker *make) {
           make.left.equalTo(grayView.left).offset(20);
           make.centerY.equalTo(grayView.centerY);
       }];
        
        
    UIView *pointView = UIView.new;
    [self addSubview:pointView];

    pointView.userInteractionEnabled = YES;
//    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goToPointView)];
//    [pointView addGestureRecognizer:singleTap];

    [pointView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->cycleScrollView.bottom).offset(0);
        make.left.equalTo(self.left).offset(0);
        make.right.equalTo(self.right).offset(0);
        make.bottom.equalTo(grayView.top);
    }];

    self->historyPointsLabel = UILabel.new;
        self->historyPointsLabel.textColor = UIColorFromRGB(0x898989);
    self->historyPointsLabel.font = [UIFont systemFontOfSize:15];
    [pointView addSubview:self->historyPointsLabel];

    [self->historyPointsLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(pointView.top).offset(0);
        make.left.equalTo(pointView.left).offset(30);
        make.bottom.equalTo(pointView.bottom);
    }];

    self->pointsLabel = UILabel.new;
        self->pointsLabel.textColor = UIColorFromRGB(0x898989);
    self->pointsLabel.font = [UIFont systemFontOfSize:15];
    [pointView addSubview:self->pointsLabel];

    [self->pointsLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(pointView.top).offset(0);
        make.left.equalTo(self->historyPointsLabel.right).offset(10);
        make.bottom.equalTo(pointView.bottom);
    }];


    UIImageView *pointIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"point_icon"]];
    [pointView addSubview:pointIcon];

    [pointIcon makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self->historyPointsLabel.left).offset(-5);
        make.centerY.equalTo(self->pointsLabel.centerY);
        make.width.equalTo(16);
        make.height.equalTo(16);
    }];


    UIImageView *goViewIcon = UIImageView.new;
    goViewIcon.image = [UIImage imageNamed:@"go"];
    [pointView addSubview:goViewIcon];

    [goViewIcon makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(pointView.right).offset(-10);
        make.centerY.equalTo(self->pointsLabel.centerY);
        make.width.equalTo(10);
        make.height.equalTo(18.5);
    }];

//    [self initPoints];
}
    return self;
}


@end
